//
//  DownloadHeaderView.m
//  CoolFM
//
//  Created by 曹曹 on 16/9/10.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "DownloadHeaderView.h"

@interface DownloadHeaderView ()

@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UIButton *left;
@property (nonatomic, strong) UIButton *rigt;

@end

@implementation DownloadHeaderView

- (instancetype)initWithFrame:(CGRect)frame
                       Target:(nullable id)target
                leftBtnAction:(__nullable SEL)actionL
               rightBtnAction:(SEL)actionR
                controlsBlock:(Block)block  {
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpSubViewsWithTarget:target
                        leftBtnAction:actionL
                       rightBtnAction:actionR
                        controlsBlock:block];
    }
    return self;
}

+ (instancetype)downloadHeaderViewFrame:(CGRect)frame
                                 Target:(nullable id)target
                          leftBtnAction:(SEL)actionL
                         rightBtnAction:(SEL)actionR
                          controlsBlock:(Block)block {
    return [[self alloc] initWithFrame:frame
                                Target:target
                         leftBtnAction:actionL
                        rightBtnAction:actionR
                         controlsBlock:block];
}
- (void)setUpSubViewsWithTarget:(nullable id)target
                  leftBtnAction:(SEL)actionL
                 rightBtnAction:(SEL)actionR
                  controlsBlock:(Block)block {
    _title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds))];
    _left = [UIButton buttonWithType:UIButtonTypeCustom];
    [_left setFrame:CGRectMake(CGRectGetWidth([UIScreen mainScreen].bounds) - 60, 0, 10, CGRectGetHeight(self.bounds))];
    [_left addTarget:target action:actionL forControlEvents:UIControlEventTouchUpInside];
    _rigt = [UIButton buttonWithType:UIButtonTypeCustom];
    [_rigt setFrame:CGRectMake(CGRectGetWidth([UIScreen mainScreen].bounds) - 20, 0, 10, CGRectGetHeight(self.bounds))];
    [_rigt addTarget:target action:actionR forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_title];
    [self addSubview:_left];
    [self addSubview:_rigt];
    block(_title, _left, _rigt);
}

@end
